﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommHelper
{
    public sealed class SoundPlayerHelper
    {
        System.Media.SoundPlayer player;

        private SoundPlayerHelper()
        {
            player = new System.Media.SoundPlayer();
        }

        private static SoundPlayerHelper _SoundPlayerHelper;
        public static SoundPlayerHelper Instance
        {
            get
            {
                if (_SoundPlayerHelper == null)
                {
                    _SoundPlayerHelper = new SoundPlayerHelper();
                }
                return _SoundPlayerHelper;
            }
        }

        /// <summary>
        /// 播放语音流                                           CV                                                                                                                                         
        /// </summary>
        /// <param name="readbytes"></param>
        public void Play(byte[] readbytes)
        {
            if (readbytes == null) return;
            player.Stream = new System.IO.MemoryStream();
            player.Stream.Write(readbytes, 0, readbytes.Length);
            player.Stream.Position = 0;
            player.Play();
        }
    }
}
